
import React from 'react';
import PropTypes from 'prop-types';
import { Button, Dropdown, Icon, Menu } from 'antd';
import styles from './action.less';

class BatchAction extends React.Component {
  static propTypes = {
    onExport: PropTypes.func,
    onDownloadImportTemp: PropTypes.func,
    onImport: PropTypes.func,
  }

  _handleExport = () => {
    const { onExport } = this.props;
    typeof onExport === 'function' && onExport();
  }

  _handleDownloadImportTemp = () => {
    const { onDownloadImportTemp } = this.props;
    typeof onDownloadImportTemp === 'function' && onDownloadImportTemp();
  }

  _handleImport = () => {
    const { onImport } = this.props;
    typeof onImport === 'function' && onImport();
  }

  _generateImportActionMenus = () => {
    return (
      <Menu>
        <Menu.Item key="downloadTemp">下载模板</Menu.Item>
        <Menu.Item key="import">导入</Menu.Item>
      </Menu>
    );
  }

  render () {
    return (
      <div className={styles.batchBtns}>
        <Dropdown overlay={this._generateImportActionMenus()}>
          <Button className={styles.item}>
            批量导入 <Icon type="down" />
          </Button>
        </Dropdown>

        <Button type="primary" onClick={this._handleExport} >导出</Button>
      </div>
    );
  }
}

export default BatchAction;
